/*
 *代码由框架生成,任何更改都可能导致被代码生成器覆盖
 *如果要增加方法请在当前目录下Partial文件夹Luxs_rfqController编写
 */
using Microsoft.AspNetCore.Mvc;
using VOL.Core.Controllers.Basic;
using VOL.Entity.AttributeManager;
using MyErp.IServices;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;
using System;
using VOL.Core.DBManager;
using VOL.Core.ManageUser;
using System.Linq;
using System.Collections.Generic;
using VOL.Core.Extensions;
using System.Collections;
using Microsoft.AspNetCore.Authorization;

namespace MyErp.Controllers
{
    [Route("api/Luxs_rfq")]
    [PermissionTable(Name = "Luxs_rfq")]
    public partial class Luxs_rfqController : ApiBaseController<ILuxs_rfqService>
    {
        public Luxs_rfqController(ILuxs_rfqService service)
        : base(service)
        {
        }
       /* private WebResponseContent webResponse = new WebResponseContent();
        [HttpPost, Route("New_rfq")]//,AllowAnonymous
        public WebResponseContent New_rfq(string part_nos,string supper_nos)
        {
            //Console.WriteLine(part_nos);
            string[] part_nos_array=part_nos.Split(',');
            string[] supper_nos_array = supper_nos.Split(',');
            string now_d = DateTime.Now.ToString("yyMMdd").ToString();
            string yy = now_d.ToString().Substring(0, 2);
            string mm= now_d.ToString().Substring(2, 2);
            string dd = now_d.ToString().Substring(4, 2);
            //用到了Convert.ToDateTime，先转换为list表后再，where中使用Convert.ToDateTime，否则报错
            int co = DBServerProvider.DbContext.Set<Luxs_rfq>().ToList().Where(w => Convert.ToDateTime(w.CreateDate).ToString("yyMMdd") == now_d).Count();
           // int co = DBServerProvider.DbContext.Set<Luxs_rfq>().Where(w => Convert.ToDateTime(w.CreateDate).ToString("yyMMdd") == now_d).ToList().Count();
            foreach (var part in part_nos_array)
            {
                foreach (var supp in supper_nos_array)
                {
                    co = co + 1;
                    Luxs_rfq luxs_Rfq = new Luxs_rfq();
                    luxs_Rfq.part_no = part;
                    luxs_Rfq.supp_no = supp;
                    luxs_Rfq.ishiddencust = 1;
                    luxs_Rfq.ishiddenpname = 1;
                    luxs_Rfq.CreateDate = DateTime.Now;
                    luxs_Rfq.Creator =  UserContext.Current.GetUserInfo(UserContext.Current.UserId).UserTrueName;//用户真实名称
                    luxs_Rfq.CreateID = UserContext.Current.UserId;
                    luxs_Rfq.rfq_no = "RFQ-" + yy + mm + dd+"-"+co;
                    DBServerProvider.DbContext.Update(luxs_Rfq);
                    
                 }
            }
            DBServerProvider.DbContext.SaveChanges();
            
            return webResponse.OK("生成RFQ成功！");
        }

        [HttpPost, Route("get_rfq_all"),AllowAnonymous]//,AllowAnonymous
        public object get_rfq_all(string rfq_no)
        {
            Hashtable rtn_hst = new Hashtable();

            Luxs_rfq luxs_rfq= new Luxs_rfq();
            luxs_rfq=DBServerProvider.DbContext.Set<Luxs_rfq>().Where(s => s.rfq_no == rfq_no).FirstOrDefault();
            rtn_hst.Add("luxs_rfq", luxs_rfq);

            Erp_mara mara =new Erp_mara();
            mara = DBServerProvider.DbContext.Set<Erp_mara>().Where(s => s.matnr == luxs_rfq.part_no).FirstOrDefault();
            rtn_hst.Add("mara", mara);

            Erp_supper supper = new Erp_supper();
            supper = DBServerProvider.DbContext.Set<Erp_supper>().Where(s => s.lifnr == luxs_rfq.supp_no).FirstOrDefault();
            rtn_hst.Add("supper", supper);

            Luxs_project project = new Luxs_project();

            //Luxs_rfq_receipt luxs_Rfq_Receipt = new Luxs_rfq_receipt(); //接受清单没有的先插入,是为后面可以再修改

            int part_js_co_rec_cout = DBServerProvider.SqlDapper.QueryList<int>("select count(*) from luxs_part_js_rec_view where rfq_no=@rfq_no",new { rfq_no }).ToList()[0];
            if (part_js_co_rec_cout == 0)
            {     
                List <Luxs_js_for_mara> list_part_mara= DBServerProvider.DbContext.Set<Luxs_js_for_mara>().Where(s => s.mara_id == mara.mara_id).ToList();
                foreach (var item in list_part_mara)
                {
                    Luxs_rfq_receipt luxs_Rfq_Receipt = new Luxs_rfq_receipt();
                    luxs_Rfq_Receipt.rfq_no = rfq_no;
                    luxs_Rfq_Receipt.receipt_id = item.luxs_js_for_mara_id;//零件技术资料uuid
                    DBServerProvider.DbContext.Update(luxs_Rfq_Receipt);
                };
                DBServerProvider.DbContext.SaveChanges();
                //Luxs_js_for_mara luxs_Js_For_Mara = new Luxs_js_for_mara();
            }




            return rtn_hst;
        }*/
    }
}

